1
|
|
|
// Generated by dts-bundle-generator v9.5.1 |
2
|
|
|
|
3
|
|
|
declare namespace wsc { |
4
|
|
|
interface DataObject { |
5
|
|
|
[key: string]: any; |
6
|
|
|
} |
7
|
|
|
type WSEvent = "open" | "message" | "close" | "error"; |
8
|
|
|
/** Minimal socket-like interface. */ |
9
|
|
|
interface Socket { |
10
|
|
|
readyState: number; |
11
|
|
|
send(...any: any[]): void; |
12
|
|
|
close(): void; |
13
|
|
|
addEventListener(event: string, handler: ((event: any) => any), ...any: any[]): void; |
14
|
|
|
} |
15
|
|
|
type AsyncErrCode = Promise<number | null | {}>; |
16
|
|
|
type EventHandler = (e: any) => void; |
17
|
|
|
type DataPipe = (message: any) => any; |
18
|
|
|
type DataType = "json" | "string"; |
19
|
|
|
interface Config { |
20
|
|
|
data_type: DataType; |
21
|
|
|
log(event: string, time?: number | null, message?: any): void; |
22
|
|
|
log(event: string, message?: any): void; |
23
|
|
|
timer: boolean; |
24
|
|
|
url: string; |
25
|
|
|
timeout: number; |
26
|
|
|
reconnect: number; |
27
|
|
|
lazy: boolean; |
28
|
|
|
socket: Socket | null; |
29
|
|
|
adapter: (host: string, protocols?: string[]) => Socket; |
30
|
|
|
encode: (key: string, message: any, config: Config) => any; |
31
|
|
|
decode: (rawMessage: any) => { |
32
|
|
|
[id_or_data_key: string]: string; |
33
|
|
|
}; |
34
|
|
|
protocols: string[]; |
35
|
|
|
pipes: DataPipe[]; |
36
|
|
|
server: { |
37
|
|
|
id_key: string; |
38
|
|
|
data_key: string; |
39
|
|
|
}; |
40
|
|
|
ping: { |
41
|
|
|
interval: number; |
42
|
|
|
content: any; |
43
|
|
|
}; |
44
|
|
|
} |
45
|
|
|
type UserConfig = Partial<Config>; |
46
|
|
|
interface SendOptions { |
47
|
|
|
top: any; |
48
|
|
|
data_type: DataType; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
export declare class WebSocketClient { |
52
|
|
|
private open; |
53
|
|
|
private ws; |
54
|
|
|
private forcibly_closed; |
55
|
|
|
private reconnect_timeout; |
56
|
|
|
private queue; |
57
|
|
|
private messages; |
58
|
|
|
private onReadyQueue; |
59
|
|
|
private onCloseQueue; |
60
|
|
|
private handlers; |
61
|
|
|
private config; |
62
|
|
|
private init_flush; |
63
|
|
|
private log; |
64
|
|
|
private initSocket; |
65
|
|
|
private connect; |
66
|
|
|
get socket(): wsc.Socket | null; |
67
|
|
|
ready(): Promise<void>; |
68
|
|
|
on(event_name: wsc.WSEvent, handler: (data: any) => any, predicate?: (data: any) => boolean, raw?: boolean): number | void; |
69
|
|
|
close(): wsc.AsyncErrCode; |
70
|
|
|
/** .send(your_data) wraps request to server with {id: `hash`, data: `actually your data`}, |
71
|
|
|
returns a Promise that will be rejected after a timeout or |
72
|
|
|
resolved if server returns the same signature: {id: `same_hash`, data: `response data`}. |
73
|
|
|
*/ |
74
|
|
|
send<RequestDataType = any, ResponseDataType = any>(message_data: RequestDataType, opts?: wsc.SendOptions): Promise<ResponseDataType>; |
75
|
|
|
constructor(user_config?: wsc.UserConfig); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
export { |
79
|
|
|
WebSocketClient as default, |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
export {}; |
83
|
|
|
|